/*
 * @# PhotosFavorsController.java 2011-12-28 下午04:57:43
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.px.album.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ianswer.common.util.Feedback;
import com.ianswer.px.album.service.PhotoFavorService;
import com.ianswer.px.common.SessionContextHolder;
import com.ianswer.px.common.annotation.SessionAware;

/**
 * 相片收藏.
 * 
 * @author alvin hwang
 */
@SessionAware
@Controller
public class PhotosFavorsController {

	@Resource(name = "photoFavorService")
	private PhotoFavorService photoFavorService;
	
	@RequestMapping(value = "/albums/favors/photos", method = RequestMethod.GET)
	public String photoFavors(Model model) {
		Long userId = SessionContextHolder.getUserId();
		model.addAttribute("favors", photoFavorService.queryFirstPageByUser(userId));
		return "album/favor/photos";
	}
	
	@RequestMapping(value = "/albums/favors/photos/page/{pageIndex}", method = RequestMethod.GET)
	public String photoFavorsPage(@PathVariable("pageIndex") int pageIndex, Model model) {
		Long userId = SessionContextHolder.getUserId();
		model.addAttribute("favors", photoFavorService.queryByUser(userId, pageIndex));
		return "album/favor/albums";
	}
	
	@RequestMapping(value = "/albums/{albumId}/favors/photos/{photoId}/create", method = RequestMethod.POST)
	public @ResponseBody Feedback createFavors(@PathVariable("albumId") Long albumId, @PathVariable("photoId") Long photoId) {
		Long userId = SessionContextHolder.getUserId();
		photoFavorService.insert(albumId, photoId, userId);
		return Feedback.success("t");
	}
	
	@RequestMapping(value = "/albums/{albumId}/favors/photos/{photoId}/remove", method = RequestMethod.POST)
	public @ResponseBody Feedback removeFavors(@PathVariable("albumId") Long albumId, @PathVariable("photoId") Long photoId) {
		Long userId = SessionContextHolder.getUserId();
		photoFavorService.delete(albumId, photoId, userId);
		return Feedback.success("t");
	}
}
